#region File information

/**
 * File: ClientJoinedPacket.cs
 * Date: 16-03-2008
 * Auth: Jan-Jaap Severs
 * 
 * Desc: A ClientJoinedPacket is sent by the server to a newly-joined client to inform him of
 *       server-side IDs etc.
 */

#endregion

#region Using statements

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.GamerServices;

#endregion

// TODO:
// Send this packet to one client only!

namespace Squadron.Networking
{
    class ClientJoinedPacket
    {
        #region Header information

        /// This packet's type.
        PacketType packetType = PacketType.ClientJoined;

        #endregion

        UInt16 id;

        public ClientJoinedPacket(UInt16 id)
        {
            this.id = id;
        }

        public void Write(PacketWriter packetWriter, SendDataOptions sendDataOptions, LocalNetworkGamer server,
            NetworkGamer recipient)
        {
            // Write the header
            packetWriter.Write((int)packetType);

            packetWriter.Write(id);

            // Send the data across the network.
            server.SendData(packetWriter, sendDataOptions, recipient);
        }

        public static ClientJoinedPacket Read(LocalNetworkGamer gamer, PacketReader packetReader)
        {
            UInt16 id = packetReader.ReadUInt16();

            return new ClientJoinedPacket(id);
        }

        public UInt16 ID
        {
            get { return id; }
        }
    }
}
